package Lee_code;

import java.util.*;

/**
 * @author blh
 * @date 2024年08月14日 21:34
 */
public class Lee_438_814 {
    public List<Integer> findAnagrams(String s, String p) {
        List<Integer> res = new ArrayList<>();
        int len = p.length();
        int l = 0;
        char[] chars = s.toCharArray();
        List<Character> list = new ArrayList<>();
        for (char aChar : p.toCharArray()) {
            list.add(aChar);
        }
        Collections.sort(list);


        for (int r = len; r <= chars.length; r++) {
            if (!list.contains(chars[r])) {
                r = r + 3;
                continue;
            }
            String temp = s.substring(r - len, r);
            char[] tempChars = temp.toCharArray();
            List<Character> tempList = new ArrayList<>();
            for (char tempChar : tempChars) {
                tempList.add(tempChar);
            }
            Collections.sort(tempList);
            if (tempList.equals(list)) {
                res.add(r - len);
            }
        }
        return res;
    }
}
